﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsMine.Storage;

namespace NewsDiscoveryEngine
{
    public class JobsManager
    {
        static List<JobEngine> jobEngines;

        public void ProcessJobsByJobEngine()
            {
            JobEngine jobEngine = new JobEngine();
            jobEngine.AgentName = "local";
            jobEngine.EngineRecycleTimeSpan = new TimeSpan(0, 20, 0); //Being this is going to run in the windows service or windows forms app, we can have log duration.
            jobEngine.ID = Guid.NewGuid().ToString("N");
            jobEngine.JobTrackingService = new JobTrackingService();
            jobEngine.keyStoreClient = Defaults.DefaultKeyValueStore;
            jobEngine.QueueClient = Defaults.JobQueue;

            jobEngine.StartTime = DateTime.UtcNow;
            jobEngine.JobEngineStopped += new JobEngine.JobEngineStoppedDelegate(jobEngine_JobEngineStopped);

            if (jobEngines == null)
                jobEngines = new List<JobEngine>();

            jobEngines.Add(jobEngine);

            jobEngine.ProcessJobs();

            
        }

        public void ProcessDownloadingJobsByJobEngine()
        {
            JobEngine jobEngine = new JobEngine();
            jobEngine.AgentName = "local";
            jobEngine.EngineRecycleTimeSpan = new TimeSpan(0, 20, 0); //Being this is going to run in the windows service or windows forms app, we can have log duration.
            jobEngine.ID = Guid.NewGuid().ToString("N");
            jobEngine.JobTrackingService = new JobTrackingService();
            jobEngine.keyStoreClient = Defaults.DefaultKeyValueStore;
            jobEngine.QueueClient = Defaults.DownloadingJobQueue;

            jobEngine.StartTime = DateTime.UtcNow;
            jobEngine.JobEngineStopped += new JobEngine.JobEngineStoppedDelegate(jobEngine_JobEngineStopped);

            if (jobEngines == null)
                jobEngines = new List<JobEngine>();

            jobEngines.Add(jobEngine);

            jobEngine.ProcessJobs();


        }

        static void jobEngine_JobEngineStopped(JobEngine jobEngine)
        {
            //todo: needs to be implemented.
        }

        public static void StopJobEngineById(string id)
        {

        }

        public static void AssignQueueToAgent()
        {
            //todo: needs to be implemeted.
        }

        public static void AddNewJobEngineInstance(string queueName)
        {

        }

        public static void ChangeInputQueueCriteria()
        {
            /* 
             This method will be used to changed the priority and process any emergency items in the queue.
             but the current queue (file systemd based queue) is not supporting any critiria stuff.
         
             * this could be future option, when we use lucene as quest store.
         
             
             */
        }

    }
}
